package com.ruoyi.merchant.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.Merchant;
import com.ruoyi.merchant.service.IMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商家管理Controller
 */
@RestController
@RequestMapping("/merchant/merchant")
public class MerchantController extends BaseController {

    @Autowired
    private IMerchantService merchantService;

    /**
     * 查询自动接单设置
     */
    @GetMapping("/auto-accept-setting")
    public AjaxResult getAutoAcceptSetting() {
        Merchant merchant = merchantService.getAutoAcceptSetting();
        return success()
            .put("autoAcceptOrder", merchant.getAutoAcceptOrder())
            .put("autoAcceptTime", merchant.getAutoAcceptTime());
    }

    /**
     * 更新自动接单设置
     */
    @Log(title = "自动接单设置", businessType = BusinessType.UPDATE)
    @PutMapping("/auto-accept-setting")
    public AjaxResult updateAutoAcceptSetting(@RequestBody java.util.Map<String, Object> params) {
        Integer autoAcceptOrder = (Integer) params.get("autoAcceptOrder");
        Integer autoAcceptTime = (Integer) params.get("autoAcceptTime");
        return toAjax(merchantService.updateAutoAcceptSetting(autoAcceptOrder, autoAcceptTime));
    }
}
